package com.jming.jike.controller.front;

import com.jming.jike.common.ResponseResult;
import com.jming.jike.common.ValidatorGroup.Insert;
import com.jming.jike.common.ValidatorGroup.Update;
import com.jming.jike.dto.front.ShoppingCartDTO;
import com.jming.jike.service.front.ShoppingCartService;
import com.jming.jike.vo.front.ShoppingCartDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author jinming.zhang
 * @version 0.0.1
 * @date 2022/05/05
 */
@RestController
@RequestMapping("/shoppingCart")
@Api(tags = "购物车相关接口", value = "/shoppingCart")
public class ShoppingCartController {

    @Resource
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation(value = "添加购物车", notes = "添加购物车", produces = "application/json", httpMethod = "POST")
    public ResponseResult<Boolean> add(@RequestBody @Validated(Insert.class) ShoppingCartDTO shoppingCartDTO) {

        return ResponseResult.success(shoppingCartService.add(shoppingCartDTO));
    }

    @PutMapping("/cut")
    @ApiOperation(value = "删减购物车", notes = "删减购物车", produces = "application/json", httpMethod = "PUT")
    public ResponseResult<Boolean> cut(@RequestBody @Validated(Update.class) ShoppingCartDTO shoppingCartDTO) {

        return ResponseResult.success(shoppingCartService.cut(shoppingCartDTO));
    }

    @DeleteMapping("/clean")
    @ApiOperation(value = "清空购物车", notes = "清空购物车", produces = "application/json", httpMethod = "DELETE")
    public ResponseResult<Boolean> clean() {

        return ResponseResult.success(shoppingCartService.clean());
    }

    @GetMapping("/list")
    @ApiOperation(value = "购物车详情", notes = "购物车详情", produces = "application/json", httpMethod = "GET")
    public ResponseResult<ShoppingCartDetailVO> list() {

        return ResponseResult.success(shoppingCartService.list());
    }

}
